﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace zuoweishigefeiwu1
{
    public partial class zuoweiTools : Form
    {
        public zuoweiTools()
        {
            InitializeComponent();
        }

        public DirectoryInfo TheFolder { get; private set; }

        private void button1_Click(object sender, EventArgs e)
        {
            DirectoryInfo TheFolder = new DirectoryInfo(textBoxfolder.Text);


            //遍历文件
            foreach (FileInfo NextFile in TheFolder.GetFiles())
            {
                if (NextFile.Name.EndsWith(".txt"))
                {

                    using (StreamReader sr = new StreamReader(NextFile.FullName))
                    {

                        string str = sr.ReadToEnd();
                        sr.Close();
                        str=str.Replace(textBoxolder.Text, textBoxNewer.Text);
                        System.IO.File.WriteAllText(NextFile.FullName, str);
                    }
                }
            }


        }

        private void buttonLoadPic_Click(object sender, EventArgs e)
        {
            FolderDialog openFolder = new FolderDialog();
            if (openFolder.DisplayDialog() == DialogResult.OK)
            {
                label4.Text = openFolder.Path.ToString();
                TheFolder = new DirectoryInfo(label4.Text);
                foreach (DirectoryInfo NextFolder in TheFolder.GetDirectories())
                    this.listBox1.Items.Add(NextFolder.Name);

            }
            else
            {
                label4.Text = "你没有选择目录";
            }



        }

        private void buttonWork_Click(object sender, EventArgs e)
        {
            if (TheFolder == null)
                MessageBox.Show("TheFolder == null");

            string t = textBoxItem.Text;
            Console.WriteLine("textBoxItem.Text: "+t);

            foreach (DirectoryInfo NextFolder in TheFolder.GetDirectories()) {

                foreach (FileInfo NextFile in NextFolder.GetFiles()) {

                    if (NextFile.Name == t) {

                        Console.WriteLine("get One: " + t);
                        string Dictionaryname = NextFile.DirectoryName;
                       // string n = NextFile.FullName;
                        string destFileName = Dictionaryname+@"\" +NextFolder.Name +  NextFile.Extension;
                        File.Move(NextFile.FullName, destFileName);
                    }

                }
            }


        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

